package com.ruoyi.web.controller.core;

import java.util.Calendar;
import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.utils.DictUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.core.domain.Shop;
import com.ruoyi.core.service.IShopService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网点列表Controller
 * 
 * @author lgc
 * @date 2020-08-07
 */
@Controller
@RequestMapping("/core/shop")
public class ShopController extends BaseController
{
    private String prefix = "core/shop";

    @Autowired
    private IShopService shopService;

    @RequiresPermissions("core:shop:view")
    @GetMapping()
    public String shop()
    {
        return prefix + "/shop";
    }

    /**
     * 查询网点列表列表
     */
    @RequiresPermissions("core:shop:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Shop shop)
    {
        startPage();
        shop.setUserId(ShiroUtils.getUserId());
        List<Shop> list = shopService.selectShopList(shop);
        return getDataTable(list);
    }

    /**
     * 导出网点列表列表
     */
    @RequiresPermissions("core:shop:export")
    @Log(title = "网点列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Shop shop)
    {
        List<Shop> list = shopService.selectShopList(shop);
        ExcelUtil<Shop> util = new ExcelUtil<Shop>(Shop.class);
        return util.exportExcel(list, "shop");
    }

    /**
     * 新增网点列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存网点列表
     */
    @RequiresPermissions("core:shop:add")
    @Log(title = "网点列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Shop shop)
    {
        shop.setUserId(ShiroUtils.getUserId());
        shop.setLastUpdatedBy(ShiroUtils.getUserId());
        logger.info("获取参数值shop={}",shop);
        return toAjax(shopService.insertShop(shop));
    }

    /**
     * 修改网点列表
     */
    @GetMapping("/edit/{shopId}")
    public String edit(@PathVariable("shopId") Long shopId, ModelMap mmap)
    {
        Shop shop = shopService.selectShopById(shopId);
        mmap.put("shop", shop);
        return prefix + "/edit";
    }

    /**
     * 修改保存网点列表
     */
    @RequiresPermissions("core:shop:edit")
    @Log(title = "网点列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Shop shop)
    {
        return toAjax(shopService.updateShop(shop));
    }

    /**
     * 删除网点列表
     */
    @RequiresPermissions("core:shop:remove")
    @Log(title = "网点列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopService.deleteShopByIds(ids));
    }
}
